<?php
/*


/-----------------------------------------------\
|          CODE by Kirati Isarapungpun          |
|       For North - Chiang Mai University       |
|       Software Engineering Project 2013       |
|                                               |
|  |-|>===================================<|-|  |
|                                               |
|       Course planning for Bachelor of         |
| Science degree in software engineering 2012   | 
|      Faculty of Science and Technology,       |
|        North - Chiang Mai University          |
|                                               |
\-----------------------------------------------/

/												\
		Deparment	:	Class deparment    
\												/

*/

	class Deparment
	{
		private $id;
		private $number;
		private $name;
		
		function __construct()
		{
			
		}
		
		function getID()
		{
			return $this->id;
		}
		
		function setID($set)
		{
			$this->id = $set;
		}
		
		function getNember()
		{
			return $this->number;
		}
		
		function setNumber($set)
		{
			$this->number = $set;
		}
		
		function getName()
		{
			return $this->name;
		}
		
		function setName($set)
		{
			$this->name = $set;
		}
		
		function setAll($id,$number,$name)
		{
			$this->id = $id;
			$this->number = $number;
			$this->name = $name;
		}
		
		function findOne()
		{
			$query = mysql_query('SELECT D_name,D_number FROM deparment WHERE D_id = "'.$this->id.'" LIMIT 1')or die(mysql_error());
			$arr = mysql_fetch_object($query);
			$this->name = $arr->D_name;
			$this->number = $arr->D_number;
			return($this->name);
		}
		
		function findAll()
		{
			$query = mysql_query('SELECT D_id,D_name,D_number FROM deparment')or die(mysql_error());
			$data_array = array();
			while($arr = mysql_fetch_object($query))
			{
				$data_array[$arr->D_id]['id'] = $arr->D_id;
				$data_array[$arr->D_id]['name'] = $arr->D_name;
				$data_array[$arr->D_id]['number'] = $arr->D_number;
			}
			return json_encode($data_array);
		}
		
		function add()
		{
			mysql_query('INSERT INTO deparment(D_name,D_number) VALUES("'.$this->name.'","'.$this->number.'")')or die(mysql_error());
		}
		
		function edit()
		{
			mysql_query('UPDATE deparment SET D_name="'.$this->name.'",D_number="'.$this->number.'" WHERE D_id = "'.$this->id.'" LIMIT 1')or die(mysql_error());
		}
		
		function del()
		{
			mysql_query('DELETE FROM deparment WHERE D_id="'.$this->id.'" LIMIT 1') or die(mysql_error());
		}
		
	}
?>